package com.jeasonzhao.report.engine;

import java.util.Date;
import com.jeasonzhao.commons.utils.CryptUtil;
import com.jeasonzhao.commons.xml.XMLNode;
import com.jeasonzhao.commons.xml.XMLHelper;
import com.jeasonzhao.commons.utils.ConvertEx;

public class License implements java.io.Serializable
{
    private static final long serialVersionUID = 1L;
    private java.util.Date beginDate = null;
    private java.util.Date endDate = null;
    private int threadsCound = 10;
    private boolean usingCache = false;
    private boolean usingCustomize = false;
    public License(String initString)
    {
        try
        {
            if(null == initString || initString.length() < 1)
            {
                return;
            }
            initString = CryptUtil.advanceDecrypt(initString);
            XMLNode nodeRoot = XMLHelper.fromString(initString);
            this.beginDate = ConvertEx.toDate(nodeRoot.subItemOrValueOf(
                "StartDate","BeginDate"),new Date());
            this.endDate = ConvertEx.toDate(nodeRoot.subItemOrValueOf(
                "endDate","StopDate"),new Date());
            this.threadsCound = ConvertEx.toInt(nodeRoot.subItemOrValueOf(
                "Thread","ThreadCount","ThreadAmount"
                ,"Process","ProcessCount","ProcessAmount"),10);
            this.usingCache = ConvertEx.toBoolN(nodeRoot.subItemOrValueOf(
                "CACHE","UsingCACHE","IsCACHE","isCACHEUsed"),false);
            this.usingCustomize = ConvertEx.toBoolN(nodeRoot.subItemOrValueOf(
                "CUSTOMIZE","UsingCUSTOMIZE","IsCUSTOMIZE","isCUSTOMIZEUsed")
                ,false);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
            this.endDate = null;
            this.beginDate = null;
            this.usingCache = false;
            this.usingCustomize = false;
        }
    }

    public Date getBeginDate()
    {
        return beginDate;
    }

    public Date getEndDate()
    {
        return endDate;
    }

    public boolean isValidate()
    {
        return null != this.beginDate && null != this.endDate
            && this.beginDate.compareTo(new java.util.Date()) < 0
            && this.endDate.compareTo(new java.util.Date()) > 0;
    }

    public int getThreadsCound()
    {
        return threadsCound;
    }

    public boolean isUsingCache()
    {
        return usingCache;
    }

    public boolean isUsingCustomize()
    {
        return usingCustomize;
    }

}
